using System.Collections.Generic;
using System.Threading.Tasks;
using GameKit.Core;
using GameKitUnity.Core;
using GameKitUnity.UI;
using UnityEngine;

namespace OneGame
{
    public class PreloadController : MonoBehaviour
    {
        [SerializeField]
        private PreloadConfig preloadConfig;

        private readonly List<Task> _tasks = new();

        private async void Start()
        {
            UIKit.Instance.Clear();
            AssetLoader.Instance.SetContextAndRelease("CombatContext");
            foreach (var config in preloadConfig.preloads)
            {
                var task = PoolManager.Instance.Create(this, config.name, config.asset, config.preloadCount);
                _tasks.Add(task);
            }

            await Task.WhenAll(_tasks);
            Log.Info("Preload completed!");
            SceneManager.Instance.LoadScene("CombatScene");
        }
    }
}